package com.ftz.examinationsystem.controller;

import com.ftz.examinationsystem.pojo.Room;
import com.ftz.examinationsystem.pojo.showinfo;
import com.ftz.examinationsystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class URLController {
    @Autowired
    UserService userService;



    @GetMapping("/")
    public String index(){
        return "index";
    }

    @GetMapping("/welcome")
    public String welcome(){
        return "welcome";
    }

    @GetMapping("student/add")
    public String add(){
        return "student/addStu";
    }

    @GetMapping("student/show")
    public String show(){
        return "student/showAll";
    }

    @GetMapping("room/add")
    public String addroom(){
        return "room/addRoom";
    }

    @GetMapping("room/list")
    public String roomlist(){
        return "room/RoomList";
    }

    @GetMapping("exam/unifiedArrage")
    public String unified(Model model,String course){
        List<Integer> integers = userService.countStus(course);
        List<String> roomAddr = userService.queryRoomAddr();
        List<Room> roomDetaile=userService.queryRoom();
        List<String> cname = userService.selectCourse();
        int sum=0,count=0;
        List<Integer> rooms = userService.countRooms();

        for(Integer i:integers){
            sum+=i;
        }
        for(Integer i:rooms){
            count+=i;
        }
        //跳转到分配设置页面并将机房名渲染到页面中
        model.addAttribute("roomAddr",roomAddr);  //存储机房地址
        model.addAttribute("room",roomDetaile);  //存储机房信息
        model.addAttribute("countStus",integers); //每个校区的人数
        model.addAttribute("totalStu",sum); //总人数
        model.addAttribute("countRoom",rooms); //每个校区机房数
        model.addAttribute("totalRoom",count); //机房总数
        model.addAttribute("cname",cname);//课程名
        return "exam/UnifiedArrange";
    }

    @GetMapping("exam/eDistribute")
    public String eDistribute(Model model){
        List<String> roomAddr = userService.queryRoomAddr();
        List<String> cname = userService.selectCourse();
        model.addAttribute("roomAddr",roomAddr); //机房地址
        model.addAttribute("cname",cname);//课程名
        return "exam/eDistribute";
    }

    @GetMapping("exam/stuDistribute")
    public String stuDistribute(Model model){
        List<String> roomAddr = userService.queryRoomAddr();
        List<String> cname = userService.selectCourse();
        model.addAttribute("roomAddr",roomAddr); //机房地址
        model.addAttribute("cname",cname);//课程名
        return "exam/stuDistribute";
    }

    @GetMapping("exam/IndividualArrage")
    public String IndividualArrage(Model model){
        List<String> roomAddr = userService.queryRoomAddr();
        List<String> cname = userService.selectCourse();
        model.addAttribute("cname",cname);//课程名
        model.addAttribute("roomAddr",roomAddr); //机房地址
        return "exam/IndividualArrage";
    }

    @GetMapping("exam/ClearRoomStu")
    public String ClearRoomStu(Model model){
        List<String> roomAddr = userService.queryRoomAddr();
        List<String> cname = userService.selectCourse();
        model.addAttribute("cname",cname);//课程名
        model.addAttribute("roomAddr",roomAddr); //机房地址
        return "exam/ClearRoomStu";
    }

    @GetMapping("exam/ChangeRoom")
    public String ChangeRoom(Model model){
        List<String> roomAddr = userService.queryRoomAddr();
        List<String> cname = userService.selectCourse();
        model.addAttribute("cname",cname);//课程名
        model.addAttribute("roomAddr",roomAddr); //机房地址
        return "exam/ChangeRoom";
    }
}
